package com.shop.service.Impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.DtsCollectMapper;
import com.shop.pojo.DtsAddress;
import com.shop.pojo.DtsCollect;
import com.shop.service.DtsCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName DtsCollectServiceImpl
 * @Author xiao宋
 * @Date 19:47  2022/10/15
 * @Version 1.0
 * @Description TODO
 */
@Service
public class DtsCollectServiceImpl implements DtsCollectService {
    @Autowired
    DtsCollectMapper collectMapper;
    @Override
    public Map<String, Object> findByPage(Integer page, Integer limit, String sort, String order, Integer valueId, Integer userId) {
        IPage<DtsCollect> iPage = new Page<>(page, limit);
        QueryWrapper<DtsCollect> w = new QueryWrapper<>();
//
        if (userId != null) {
            w.eq("user_id", userId);
        }
        if (valueId != null) {
            w.eq("value_id", valueId);
        }

        //        排序方式
        if ("desc".equalsIgnoreCase(order)) {
            w.orderByDesc(sort);
        } else {
            w.orderByAsc(sort);
        }
        collectMapper.selectPage(iPage, w);
        Map<String, Object> data = new HashMap<>();
        data.put("total", iPage.getTotal());
        data.put("items", iPage.getRecords());
        return data;
    }
}
